package by.yakusekmaxim.bookgid.datamodel;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import by.yakusekmaxim.bookgid.datamodel.enums.PublicationStatus;
import by.yakusekmaxim.bookgid.util.ImageInterface;

@Entity
public class Author extends AbstractEntity implements ImageInterface{
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column
	@Size(max = 100)
	private String nameOr;
	
	@Column
	@NotNull
	@Size(max = 100)
	private String name;
	
	@Column
	private Date yearBirth;
	
	@Column
	private Date yearDeath;
	
	@Column
	@Size(max = 100)
	private String birthplace;
	
	@Column
	private String biography;
	
	@ManyToOne(fetch = FetchType.EAGER, targetEntity = Image.class)
	private Image image;
	
	@Column
	@Enumerated(EnumType.ORDINAL)
	@NotNull
	private PublicationStatus status;


	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNameOr() {
		return nameOr;
	}

	public void setNameOr(String nameOr) {
		this.nameOr = nameOr;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getYearBirth() {
		return yearBirth;
	}

	public void setYearBirth(Date yearBirth) {
		this.yearBirth = yearBirth;
	}

	public Date getYearDeath() {
		return yearDeath;
	}

	public void setYearDeath(Date yearDeath) {
		this.yearDeath = yearDeath;
	}

	public String getBirthplace() {
		return birthplace;
	}

	public void setBirthplace(String birthplace) {
		this.birthplace = birthplace;
	}

	public String getBiography() {
		return biography;
	}

	public void setBiography(String biography) {
		this.biography = biography;
	}

	public Image getImage() {
		return image;
	}

	public void setImage(Image image) {
		this.image = image;
	}

	public PublicationStatus getStatus() {
		return status;
	}

	public void setStatus(PublicationStatus status) {
		this.status = status;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Author other = (Author) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	

}
